11. Quaternions
C2 L2 A08 Quaternions V2
Quaternion Summary
The Quaternion is another way of representing 3 dimension orientation. Instead of using three Euler Angles which describe roll, pitch, and yaw, the quaternion uses four numbers (which we label a, b, c, d).
These numbers don't have the same intuitive significance as the Euler Angles, but they can also be used to unambiguously represent orientations and rotations in three dimensions.
You can convert from one representation to the other using the following math:
Quaternion to Euler
\begin{bmatrix}
\phi \\
\theta \\
\psi
\end{bmatrix}
=
\begin{bmatrix}
\tan^{-1} \frac{2(ab+cd)}{1 - 2(b^2+c^2)} \\
\sin^{-1} 2(ac-db)\\
\tan^{-1} \frac{2(ad+bc)}{1 - 2(c^2+d^2)}
\end{bmatrix}
Euler to Quaternion
{\begin{aligned}
\begin{bmatrix}
a\\
b\\
c\\
d
\end{bmatrix}
&={\begin{bmatrix}\cos(\psi /2)\\0\\0\\\sin(\psi /2)\end{bmatrix}}{\begin{bmatrix}\cos(\theta /2)\\0\\\sin(\theta /2)\\0\end{bmatrix}}{\begin{bmatrix}\cos(\phi /2)\\\sin(\phi /2)\\0\\0\end{bmatrix}}\\&={\begin{bmatrix}\cos(\phi /2)\cos(\theta /2)\cos(\psi /2)+\sin(\phi /2)\sin(\theta /2)\sin(\psi /2)\\\sin(\phi /2)\cos(\theta /2)\cos(\psi /2)-\cos(\phi /2)\sin(\theta /2)\sin(\psi /2)\\\cos(\phi /2)\sin(\theta /2)\cos(\psi /2)+\sin(\phi /2)\cos(\theta /2)\sin(\psi /2)\\\cos(\phi /2)\cos(\theta /2)\sin(\psi /2)-\sin(\phi /2)\sin(\theta /2)\cos(\psi /2)\end{bmatrix}}\\\end{aligned}}